package sort;

import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;

/**
 * 比较堆排序和冒泡排序法的时间复杂度
 */
public class CompareHeapAndBubble {
    public static void main(String[] args) {
        int n = 100000;
        int[] arr1 = new int[n];
        //生成随机数
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for(int i=0; i<n; i++){
            arr1[i] = random.nextInt(0, Integer.MAX_VALUE);
        }
        //再复制一个一样的数组
        int[] arr2 = Arrays.copyOf(arr1, n);

        //记录系统当前时间
        Long start = System.nanoTime();
        BubbleSort.bubbleSort(arr1);
        Long end = System.nanoTime();
        //计算该排序所用时间
        Long time = (end - start) / 1000000;
        System.out.println("冒泡排序法所耗时：" + time + "ms");

        start = System.nanoTime();
        HeapSort.heapSort(arr2);
        end = System.nanoTime();
        time = (end - start) / 1000000;
        System.out.println("堆排序所耗时：" + time + "ms");
    }
}
